define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'table_qrcode/index',
                    add_url: 'table_qrcode/create_qrcode'

                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,

                searchFormVisible: true,
                commonSearch: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'qrcode_sn', title: __('qrcode_sn')},
                        {field: 'status', title: __('绑定状态'),formatter: Table.api.formatter.status, searchList: {1: __('未绑定'), 2: __('已绑定')}},
                        {field: 'sname', title:__('sname') ,search:false},
                        {field: 'table_id', title: __('table_id')},
                        {field: 'bind_time', title: __('bind_time') , formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange'},
                        {field: 'create_at', title: __('create_at') , operate: 'RANGE', addclass: 'datetimerange'},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'show',
                                text: __('show'),
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: "table_qrcode/show"
                            }],
                            formatter: Table.api.formatter.operate
                        },



                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);


            // 下载
            $(document).on("click", ".btn-down", function () {
                //在table外不可以使用添加.btn-change的方法
                //只能自己调用Table.api.multi实现
                //如果操作全部则ids可以置为空
                var ids = Table.api.selectedids(table);
                console.log(ids);
                download( ids );
                return false;
            });


        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});